package crm.model.studentPC;

import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Toolkit;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

import crm.model.studentPC.win.WindowList;
import crm.model.studentPC.win.window.Window;


public class LockThread extends Thread {
	private boolean lock = false;
	private WindowList wList;
	private JFrame lockScreen;
	public LockThread(WindowList wList) {
		this.wList=wList;


		//wList.createDesktop("lockDesktop");
	}
	public void lock(){
		if (lock == false){
			lock = true;
			//createGUI();
			start();
		}
	}
	public void unlock(){
		lock = false;
		wList.deaktivateBlockInput(false);
		//deleteGUI();

	}

	public void run(){
		while(lock){

			System.out.println("Lock: " + wList.deaktivateBlockInput(true));
			try {
				Thread.sleep(200);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}





	public void createGUI(){
		lockScreen = new JFrame();
		Cursor invisibleCursor = Toolkit.getDefaultToolkit().createCustomCursor(Toolkit.getDefaultToolkit().getImage(""), new Point(0,0), "invisible");
		lockScreen.setCursor(invisibleCursor);
		lockScreen.setUndecorated(true);
		lockScreen.setLocation(0, 0);
		final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		lockScreen.setSize(screenSize.width, screenSize.height);

		final JLabel lab = new JLabel(){
			public void paint(Graphics g) {
				g.setColor(Color.WHITE);
				g.fillRect(0, 0, screenSize.width, screenSize.height);
				g.drawImage(new ImageIcon("lock.png").getImage(), 0, 0, screenSize.width, screenSize.height, null);
			}
		};

		lockScreen.setContentPane(lab);
		lockScreen.setAlwaysOnTop(true);
		lockScreen.setVisible(true);
	}
	public void deleteGUI(){
		lockScreen.dispose();
	}

}
